//
//  runtimeControlBtnViewController.m
//  runtime
//
//  Created by ddy on 2017/12/25.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "runtimeControlBtnViewController.h"
#import "UIButton+Action.h"

#define screen_w [UIScreen mainScreen].bounds.size.width
#define screen_h [UIScreen mainScreen].bounds.size.height
#define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
@interface runtimeControlBtnViewController ()

@end

@implementation runtimeControlBtnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self uiConfig];
    
    
}
//3.通过类别创建两个按钮
//[objc] view plain copy
- (void)uiConfig{
    __weak typeof(self) weaself = self;
    
    //第一个按钮
    UIButton *button1 = [UIButton createBtnWithFrame:CGRectMake((screen_w - 100)/2, (screen_h - 50)/2 - 50, 100, 50) title:@"按钮" actionBlock:^(UIButton *button) {
        float r = random()%255/255.0;
        float g = random()%255/255.0;
        float b = random()%255/255.0;
        weaself.view.backgroundColor = RGB(r, g, b);
        NSLog(@"按钮1");
    }];
    button1.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:button1];
    
    
    

    //第二个按钮
    UIButton *button2 = [UIButton createBtnWithFrame:CGRectMake((screen_w - 100)/2, CGRectGetMaxY(button1.frame) + 50, 100, 50) title:@"按钮2" actionBlock:nil];
    button2.actionBlock = ^(UIButton *button){
        NSLog(@"---%@---",button.currentTitle);
    };
    button2.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:button2];
}
//4.获取苹果私有的APi
//这里我们也可以通过runtime获取苹果私有的方法;
//[objc] view plain copy
#pragma mark - 获取苹果私有的APi方法
//- (void)getiOSPrivateAPi{
//    NSString *className = NSStringFromClass([UIView class]);
//
//    const charchar *cClassName = [className UTF8String];
//
//    id theClass = objc_getClass(cClassName);
//
//    unsigned int outCount;
//
//    Method *m =  class_copyMethodList(theClass,&outCount);
//
//    NSLog(@"%d",outCount);
//
//    for (int i = 0; i<outCount; i++) {
//
//        SEL a = method_getName(*(m+i));
//
//        NSString *sn = NSStringFromSelector(a);
//
//        NSLog(@"%@",sn);
//    }
//}


@end
